package com.gin.kotlin.no_gay_alliance.adapter.user

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.base.GlideModule.Companion.CROSS_FADE
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.databinding.ItemMedalInUserCenterBinding
import com.gin.kotlin.no_gay_alliance.model.ItemTypeModel

class MedalInUserCenterAdapter(context: Context, handler: MyHandler, data: MutableList<ItemTypeModel> = mutableListOf()) :
    AbstractBindingRecyclerViewAdapter<ItemMedalInUserCenterBinding, ItemTypeModel>(context, handler, false, data) {
    /**
     * 当显示某一位置的item时的操作
     * @param holder ViewHolder
     * @param position Int
     * @param b ViewBinding
     * @param dataModel 数据对象
     */
    override fun onBindViewHolder(holder: ViewHolder<ItemMedalInUserCenterBinding>, position: Int, b: ItemMedalInUserCenterBinding, dataModel: ItemTypeModel) {
        b.tvMedalName.text = dataModel.name
        b.tvMedalDescription.text = dataModel.description
        Glide.with(context)
            .load(dataModel.url)
            .error(R.drawable.ic_gift)
            .placeholder(R.drawable.ic_gift)
            .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE))
            .into(b.ivMedal)
    }
}